import requests
from requests import exceptions  # 异常处理库
from bs4 import BeautifulSoup

import re

from tkinter import *
import tkinter.messagebox  # 这个是消息框，对话框的关键

from lxml import etree

import threading  # 线程

import win32gui
import win32con
import time
import sys

import json

import socket  # 获取计算机名
import uuid  # 获取make地址


from playsound import playsound  # 播放声音



#软件相关
ver = "v0.2.3"
biaoti = "线索小助手"+ver
TK = '030A3424615563F8D16BAC63A6A60CF7'+ver
font = ("微软雅黑", 14)  # 界面控件的字体及大小
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36"}#请求头
FG = ' '#信息分隔符号
on_B = False  # 是否点击按钮的判断
shuliang = '0'  # 查询到五菱平台数量
shuliangBj = '0'  # 查询到骏客平台数量
STATUS_T = '助手状态：'
LOOP_ST = '查询次数：'
WL_ST='五菱线索：'
JK_ST='骏客线索：'

searchTime = 120  # 查询间隔的时间
timeout=5 # 网页请求超时
d_num = ["0","0"]  # 气泡消息的线索数量参数
s = requests.Session()  # 网页请求
s.headers.update(headers)  # 网页请求头信息
REGIP_URL="http://www.jikeyt.com/index.php/pcb/login/regip"
POSTTIME=1

# 电脑信息
regip_data = {
    'time': "0",
    'cpname': '0',
    'mac': '0',
    'st': 0,  # 状态
    'loop_sum':0#循环查询总次数
    }


#验证参数
reg_data = {'tk':TK,
            'wl_txtFwzh':'',
            'wl_txtfwzCzymc':'',
            'wl_txtfwzCzymm':'',
            'jk_username':'',
            'jk_password': '',
            'auth':'',#骏客登录后有一个验证密码后面加了 25
            'Hdn_IPAddress':''
           }

# 宝骏网址及数据
loginUrl = 'https://nbj.sgmw.com.cn/dmscloud.sysAuth/login'  # 登录的网址
authUrl = 'https://nbj.sgmw.com.cn/dmscloud.sysAuth/login/initUserData'  # 登录认证的网址
queryUrl = 'https://nbj.sgmw.com.cn/dmscloud.cluePC/ReportManagementInfo/queryClue'  # 查询的网址
#宝骏登录提交信息
loginData = {
    'username': '',
    'password': ''
}
#宝骏登录后验证信息
authData={}

queryata = {
    'dmsFuncId': 166011,
    'order': 'DESC',
    'limit': 10,
    'offset': 0,
    'filtrationdealer': 't',
    'issuedStart': '2020-07-18',
    'issuedEnd': '2020-07-18',
    'staut': '70001001',
    'invitations': '',
    'dmsFuncId': '166011',
    '_': "0"
}
# 五菱网址
LOGIN_URL = "https://promotion.sgmw.com.cn/Login.aspx"  # 登录网址
URL = "https://promotion.sgmw.com.cn/jxsd/CJQKXS/CJQKXS.aspx"  # 查询线索网址

# 五菱登录提交的参数
login_data = {"__EVENTTARGET": "",
                "__EVENTARGUMENT": "",
                "__VIEWSTATE": "",
                "__EVENTVALIDATION": "",
                "txtMac": "",
                "login": "Radio1",
                "txtFwzh": "",
                "txtfwzCzymc": "",
                "txtfwzCzymm": "",
                "btnfwzOk.x": "48",
                "btnfwzOk.y": "10",
                "txtbmmc": "",
                "txtczy": "",
                "txtCzymm": "",
                "Txt_WLSH": "",
                "Txt_WLSCZYMC": "",
                "Txt_WLSCZYMM": "",
                "HiddenField2": "",
                "HiddenField3": "",
                "tweFwzh_ClientState": "",
                "tweWlsh_ClientState": "",
                "HiddenField1": "",
                "Hdf_WLSCZYDM": "",
                "Hd_bmbh": "",
                "Hd_zbczydm": "",
                "Hdn_IP": "0.0.0.0",
                "Hdn_IPAddress": ""}

                # 五菱查询线索的提交参数
c_data = {"__EVENTTARGET": "Btn_Search",
            "__EVENTARGUMENT": "",
            "__LASTFOCUS": "",
            "__VIEWSTATE": "",
            "__PREVIOUSPAGE": "",
            "Txt_LeadsId": "",
            "Dpl_LeadsType": "",
            "Dpl_XSYXX": "2",
            "Dpl_FollowStep": "",
            "Dpl_PT": "",
            "Dpl_ZQD": "",
            "Dpl_FQD": "",
            "Dpl_KHLY": "",
            "Txt_XFSJ_Begin": "____-__-__",
            "Txt_XFSJ_End": "____-__-__",
            "Txt_CreateTime_Begin": "____-__-__",
            "Txt_CreateTime_End": "____-__-__",
            "Txt_DealerId": "",
            "Txt_CustName": "",
            "Txt_CustMobileNum": "",
            "Txt_BrandId": "",
            "Txt_SeriesId": "",
            "Txt_ModelId": "",
            "Txt_VelVin": "",
            "Dpl_SXSHZT": "",
            "Txt_ActivityName": "",
            "Txt_PullNewMan": "",
            "Txt_PullNewManJob": "",
            "Dpl_SortMethod": "",
            "MaskedEditExtender_XFSJ_Begin_ClientState": "",
            "MaskedEditExtender_XFSJ_End_ClientState": "",
            "MaskedEditExtender_CreateTime_Begin_ClientState": ""}

# 宝骏查询


def query():
    status.set(STATUS_T+"骏客平台查询.")
    timeStamp = int(time.time())  # 获取13位的时间戳
    timeArray = time.localtime(timeStamp)
    otherStyleTime = time.strftime("%Y-%m-%d", timeArray)
    queryata['issuedStart'] = otherStyleTime
    queryata['issuedEnd'] = otherStyleTime
    queryata['_'] = timeStamp  # 修改查询的时间戳

    # 查询链接
    try:
        resget = s.get(queryUrl, params=queryata,timeout=timeout)
        resget.raise_for_status()
    except exceptions.Timeout as e:
        print("骏客超时异常")
        print(e)
        status.set(STATUS_T+"骏客异常,稍后自动重试")
        bjvar.set(JK_ST+'异常A')
        postretip(REGIP_URL,e,POSTTIME,True)#异常信息提交到后台
        return False
    except exceptions.HTTPError as e:
        print("骏客连接异常")
        print(e)
        status.set(STATUS_T+"骏客异常,稍后自动重试")
        bjvar.set(JK_ST+'异常B')
        postretip(REGIP_URL,e,POSTTIME,True)#异常信息提交到后台
        return False
    except Exception:
        print("骏客未知异常")
        status.set(STATUS_T+"骏客异常,稍后自动重试")
        bjvar.set(JK_ST+'异常C')
        postretip(REGIP_URL,401,POSTTIME,True)#异常信息提交到后台
        return False

    status.set(STATUS_T+"骏客平台查询..")
    if resget.status_code == 200:
        data = resget.text
        data = json.loads(data)
        bjvar.set(JK_ST+str(data['total']))
        status.set(STATUS_T+"骏客平台查询...")
        if data['total'] > 0:
            status.set(STATUS_T+"宝骏平台有线索")
            shuliangBj = str(data['total'])
            d_num[1] = '骏客平台有'+shuliangBj

            for item in data['rows']:
                xxly = item["THREE_LEVEL_LABEL"]  # 线索来源
                custName = item['CUSTOMER_NAME']  # 姓名
                custMobileNum = item['MOBILE_PHONE']  # 电话
                seriesId = item['SERIES_NAME']  # 意向车系
                clue = '骏客线索:'+FG+xxly+FG+custName+FG+custMobileNum+FG+seriesId
                my_text.insert(INSERT, clue)
                my_text.insert(INSERT, '\n')
                my_text.insert(INSERT, '\n')
            # 消息提醒
            
            return True
    else:

        bjvar.set('骏客平台：登录失败，无法获取')
        return False


def search():
     # 五菱的查询
    status.set(STATUS_T+"五菱线索查询.")
     # 五菱查询链接
    try:
         rhtml = s.post(URL, data=c_data,timeout=timeout)  # 查询
         rhtml.raise_for_status()
    except exceptions.Timeout as e:
            print("五菱超时异常")
            print(e)
            status.set(STATUS_T+"五菱异常,稍后自动重试")
            var.set(WL_ST+"异常A")
            postretip(REGIP_URL,e,POSTTIME,True)#异常信息提交到后台
            return False
    except exceptions.HTTPError as e:
            print("五菱连接异常")
            print(e)
            status.set(STATUS_T+"五菱异常,稍后自动重试")
            var.set(WL_ST+"异常B")
            postretip(REGIP_URL,e,POSTTIME,True)#异常信息提交到后台
            return False
    except Exception:
             print("五菱未知异常")
             status.set(STATUS_T+"五菱异常,稍后自动重试")
             var.set(WL_ST+"异常C")
             postretip(REGIP_URL,400,POSTTIME,True)#异常信息提交到后台
             return False
           

     # rhtml= s.get("http://127.0.0.1:5500/lib/test.html")#测试网址
    status.set(STATUS_T+"五菱平台查询..")
    souphtml = BeautifulSoup(rhtml.content, 'lxml')  # 查询到的数据
    
    if souphtml.find(id="Lbl_DJS").get_text() is None:
         var.set('五菱平台：登录失败，无法获取')
         return False
     
    shuliang = souphtml.find(id="Lbl_DJS").get_text()  # 查询到的数据总数
    status.set(STATUS_T+"五菱平台查询...")
    if shuliang=='':
         status.set(STATUS_T+"获取五菱平台异常，请关闭软件后重新打开")

    else:
         ts=int(shuliang)#查询到的数量改为整数
 
     
    var.set(WL_ST+shuliang)
    '''提示消息多线程方式
     if ts>0:
        d_num[0] ='五菱平台有'+shuliang
        msgtimer=threading.Thread(target=msgfun_timer,args=(d_num))
        msgtimer.daemon = True#忽略异常
        msgtimer.start()#气泡提示
     '''
     # 有线索添加到文本框并且提示
     
    if ts>0: 
        status.set(STATUS_T+"五菱平台有线索")
        tableData = souphtml.find("table", attrs={"id": "Grv_CJQKXS"})
        rows = tableData.findAll('tr')
        # 添加线索信息到文本框
        for  item in rows:
            if item.find("span") != None:
                td=item.findAll('td')
                xxly=td[5].text#线索来源
                custName=td[1].text#姓名
                custMobileNum=td[3].text#电话
                seriesId=td[9].text#意向车系
                
                clue='五菱线索:'+FG+xxly+FG+custName+FG+custMobileNum+FG+seriesId
                clue=clue.replace("\n", "")
                my_text.insert(INSERT,clue)
                my_text.insert(INSERT, '\n')
                my_text.insert(INSERT, '\n')
        
        d_num[0] ='五菱平台有'+shuliang
        #msgfun_timer()
        return True

#最终提交到后台数据
def postretip(url,st,out,msg):
        #st 状态码
        #400 五菱未知异常
        #401 骏客未知异常
        #402 五菱查询异常
        #403 骏客查询异常
        #404 开启软件验证失败
        #405 验证失败
        #406 允许的验证异常
        #407 循环验证的函数异常
        #408 循环验证异常
        #409 开启软件获取IP异常
        #410 主循环查询意外停止
        #411 骏客登录异常
        #412 骏客登录认证错误
        #413 五菱首页异常
        #414 五菱首页打开状态不对
        #415 五菱登录网页异常
        #3 循环执行状态码
        #2 软件结束状态码
        #1 软件打开
        regip_data['time']=time.time()
        regip_data['st']=st
        try:
           regip = s.post(url,data=regip_data,timeout=out)  # 软件状态提交到服务器后台
        except Exception:
            print('提交数据到服务器异常')
            pass
        if msg:
            msgyichang()


# 还有多少秒执行下一次查询
def fun_retime():
    count=0
    while(count<searchTime):
        count += 1
        n=searchTime-count
        sn=str(n)
        time.sleep(1)
        status.set(STATUS_T+sn+"秒后查询")
    status.set(STATUS_T+"开始查询.")
    try:
        regverify()
    except Exception:
        print("验证异常1")
        postretip(REGIP_URL,407,POSTTIME,False)#异常信息提交到后台
        pass

# typr 是接受一个参数 气泡消息线索数量显示
def msgfun_timer(msgwl,msgjk):
        if msgwl or msgjk:
            status.set(STATUS_T+"新线索提醒中")
            if msgwl:
                t.showMsg(d_num[0]+'条线索待处理', "线索提醒")
                time.sleep(5)
            if msgjk:
                t.showMsg(d_num[1]+'条线索待处理', "线索提醒")
                time.sleep(5)
            n = 2#x循环播放声音的次数
            counter = 1
            status.set(STATUS_T+"新线索提醒中.")
            while counter <= n:
                status.set(STATUS_T+"新线索提醒中..")
                counter += 1
                playsound(".\\static\\msg.mp3")
                status.set(STATUS_T+"新线索提醒中...")
                time.sleep(1)
        # win32gui.DestroyWindow(t.hwnd)
# 异常一次提醒
def msgyichang():
        t.showMsg('小助手查询有异常，请及时处理', "异常提醒")
        time.sleep(5)
        n = 1#x循环播放声音的次数
        counter = 1
        while counter <= n:
            counter += 1
            playsound(".\\static\\error.mp3")

# 异常多次提醒
def msgyichangloop():
        n =120 #x循环播放声音的次数
        counter = 1
        while counter <= n:
            t.showMsg('小助手意外停止，请及时处理', "提醒")
            time.sleep(30)
            counter += 1
            playsound(".\\static\\error.mp3")
        

# 循环执行查询线索
def loop_timer():
    status.set(STATUS_T+"开始查询..")
    postretip(REGIP_URL,3,POSTTIME,False)#信息提交到后台
    my_text.delete(0.0, END)#清空文本内容
    status.set(STATUS_T+"开始查询...")
    try:
        msgjk=search()#五菱查询线索
    except Exception:
        print("五菱查询异常")
        msgjk=False
        status.set(STATUS_T+"五菱查询异常")
        var.set(WL_ST+'查询异常')
        postretip(REGIP_URL,402,POSTTIME,True)#异常信息提交到后台
    try:
        msgwl=query()#宝骏查询线索
    except Exception:
         print("骏客查询异常")
         msgwl=False
         status.set(STATUS_T+"骏客查询异常")
         bjvar.set(JK_ST+'查询异常')
         postretip(REGIP_URL,403,POSTTIME,True)#异常信息提交到后台
    #线索声音和气泡提醒
    msgfun_timer(msgjk,msgwl)
    #global looptimer
    #looptimer=threading.Timer(0,loop_timer)
    fun_retime()
    #looptimer.start()
    

def one_timer():
    login()
# 查询线索

# 登录网站
def login():
        # 软件ip获取
        regip()
        # 软件验证
        regbj()
        
        # 宝骏登录
        status.set(STATUS_T+"骏客登录.")
        try:
            baojunRes = s.post(loginUrl, json=loginData,timeout=timeout)#宝骏登录
        except Exception:
            print('骏客登录异常')
            status.set(STATUS_T+"骏客无法登录")
            postretip(REGIP_URL,411,POSTTIME,True)#异常信息提交到后台
            sys.exit()

        #判断登录密码或用户名是否错误，这里成功就是登录密码和用户名没有错
        data = baojunRes.text
        data = json.loads(data)
        if 'errorMsg' in data.keys():
          print('登录用户名或密码错误')
          status.set(STATUS_T+"请修改骏客密码后再运行")
          my_text.insert(INSERT, data['errorMsg'])#把网址返回的错误信息打印到文本框
          postretip(REGIP_URL,baojunRes.text,POSTTIME,True)#异常信息提交到后台
          sys.exit()
 
        millis = str(int(round(time.time()*1000)))#获取13位的时间戳
        authData['_']=millis
        status.set(STATUS_T+"骏客登录..")
        
        try:
            auth = s.get(authUrl, params=authData,timeout=timeout)#宝骏登录后的验证
        except Exception:
            print('骏客登录认证异常')
            status.set(STATUS_T+"骏客认证异常,请关闭后重新运行")
            postretip(REGIP_URL,412,POSTTIME,True)#异常信息提交到后台
            sys.exit()
        data = auth.text
        data = json.loads(data)
        if 'errorMsg' in data.keys():
            print('骏客登录认证错误')
            status.set(STATUS_T+"骏客认证错误,请关闭后重新运行")
            my_text.insert(INSERT, data['errorMsg'])#把网址返回的错误信息打印到文本框
            postretip(REGIP_URL,baojunRes.text,POSTTIME,True)#异常信息提交到后台
            sys.exit()
        
        status.set(STATUS_T+"骏客登录...")

        # 五菱登录
        status.set(STATUS_T+"五菱登录.")
        try:
            r = s.get(LOGIN_URL,timeout=timeout)  # 打开登录页面
        except Exception:
            print('五菱网站异常')
            status.set(STATUS_T+"五菱网站异常,请关闭后重新运行")
            postretip(REGIP_URL,413,POSTTIME,True)#异常信息提交到后台
            sys.exit()
        
        
        if r.status_code==200:
            status.set(STATUS_T+"五菱登录..")
        else:
            status.set(STATUS_T+"五菱网站异常，请关闭后重新运行")
            postretip(REGIP_URL,414,POSTTIME,True)#异常信息提交到后台
            sys.exit()
        
        soup = BeautifulSoup(r.content, 'lxml')#获取登录网页的内容
          # 获取登录表单需要提交的两个值
        login_data["__VIEWSTATE"]= soup.find(id="__VIEWSTATE")['value']#获取登录表单提交数据
        login_data["__EVENTVALIDATION"]= soup.find(id="__EVENTVALIDATION")['value']#获取登录表单提交数据
        print("客户端IP"+login_data["Hdn_IP"])
        try:
            r = s.post(LOGIN_URL, data=login_data,timeout=timeout)  # 登录
        except Exception:
            print('五菱登录异常')
            status.set(STATUS_T+"五菱登录异常,请关闭后重新运行")
            postretip(REGIP_URL,415,POSTTIME,True)#异常信息提交到后台
            sys.exit()
        
        rC = s.get(URL,timeout=timeout)  # 获取查询页面数据
        if rC.status_code==200:
            status.set(STATUS_T+"五菱登录...")
        else:
            status.set(STATUS_T+"五菱登录失败，请更新密码后再试")
            postretip(REGIP_URL,416,POSTTIME,True)#异常信息提交到后台
            sys.exit()
        
        
        soupC = BeautifulSoup(rC.content, 'lxml')
        c_data['__VIEWSTATE']= soupC.find(id="__VIEWSTATE")['value']#获取查询线索提交数据
        c_data['__PREVIOUSPAGE']= soupC.find(id="__PREVIOUSPAGE")['value']#获取查询线索提交数据
        status.set(STATUS_T+"开始查询")
        #looptimer.start()#循环执行查询
        try:
           mainloop()
        except Exception:
           status.set(STATUS_T+"意外停止，请重启软件")
           postretip(REGIP_URL,410,POSTTIME,False)#异常信息提交到后台
           msgyichangloop()

def mainloop():
     loop_n=1#总共循环查询的次数
     while loop_n>=1:
        regip_data['loop_sum']=loop_n
        print('循环次数：'+str(regip_data['loop_sum']))
        loopvar.set(LOOP_ST+str(regip_data['loop_sum']))
        loop_timer()
        loop_n +=1
        

# 界面上的启动按钮执行函数
def bntc():    
    '''
    
    '''
# 软件打开的验证
def regbj():
    # 030A3424615563F8D16BAC63A6A60CF7
    status.set(STATUS_T+"安全验证.")
    try:
        regyz = s.post("http://www.jikeyt.com/index.php/pcb/login/regbj",data=reg_data,timeout=timeout)  # 打开登录页面
    except Exception:
        status.set(STATUS_T+"验证异常，请关闭软件后重新打开")
        postretip(REGIP_URL,408,POSTTIME,True)#异常信息提交到后台
        sys.exit()

    status.set(STATUS_T+"安全验证..")
    data=json.loads(regyz.text)
    if reg_data["tk"]==data["tk"]:

        #骏客登录信息赋值
        loginData['username']=data['jk_username']
        loginData['password']=data['jk_password']
        authData['password']=data['jk_password']+data['auth']
        authData[loginData['password']]=''
        
        #五菱登录信息
        login_data["txtFwzh"]=data['wl_txtFwzh']
        login_data["txtfwzCzymc"]=data['wl_txtfwzCzymc']
        login_data["txtfwzCzymm"]=data['wl_txtfwzCzymm']
        login_data["Hdn_IPAddress"]=data['Hdn_IPAddress']


        status.set(STATUS_T+"安全验证成功")
    else:
        status.set(STATUS_T+"验证失败，请及时更新软件")
        postretip(REGIP_URL,405,POSTTIME,True)#异常信息提交到后台
        sys.exit()

# 软件运行验证
def regverify():
    
    try:
         regyz = s.post("http://www.jikeyt.com/index.php/pcb/login/regbj",data=reg_data,timeout=1)  # 打开登录页面
    except Exception:
        print("验证异常")
        postretip(REGIP_URL,406,POSTTIME,False)#异常信息提交到后台
        pass
    else:
        data=json.loads(regyz.text)#接受到后台的返回数据的处理
        if reg_data["tk"]!=data["tk"]:
            status.set(STATUS_T+"验证失败，有新版本请及时更新")
            postretip(REGIP_URL,404,POSTTIME,True)#异常信息提交到后台
            sys.exit()
        if data["title"]!='':
            #如果后端标题提示信息不为空 就修改标题
             win.title(biaoti+data["title"])
        else:
             win.title(biaoti)
        if data["msgtitle"]!='':
            status.set(STATUS_T+"消息提醒中，请选择")
            res=tkinter.messagebox.askquestion(title=data["msgtitle"],message=data["message"])#提示信息对话窗
            if res=='yes': 
                  postretip(REGIP_URL,'yes',POSTTIME,False)#弹窗按钮选择信息提交到后台
            else:
                  postretip(REGIP_URL,'no',POSTTIME,False)#弹窗按钮选择信息提交到后台
                


# 打开软件是运行一次 获取当前时间搓 并提交到服务器
def regip():
    
    # 获取本机信息
    # 计算机名字
    CPNEAE = socket.gethostname()
    print(CPNEAE)
    # 获取mac地址
    addr_num = hex(uuid.getnode())[2:]
    MAC = "-".join(addr_num[i: i+2] for i in range(0, len(addr_num), 2))
    print(MAC)
    

    regip_data['time']=time.time()
    regip_data['cpname']=CPNEAE
    regip_data['mac']=MAC
    regip_data['st']=1
    try:
        regip = s.post("http://www.jikeyt.com/index.php/pcb/login/regip",data=regip_data,timeout=timeout)  # 打开登录页面
    except Exception:
        status.set(STATUS_T+"请关闭软件后重新打开")
        postretip(REGIP_URL,409,POSTTIME,True)#弹窗按钮选择信息提交到后台
        sys.exit()
    data=json.loads(regip.text)
    if data['ip'] != "0.0.0.0":
        login_data["Hdn_IP"]=data['ip']
        print('获取的ip')
        print(login_data["Hdn_IP"])
    
        
        


class TestTaskbarIcon:
    def __init__(self):
        # 注册一个窗口类
        wc = win32gui.WNDCLASS()
        hinst = wc.hInstance = win32gui.GetModuleHandle(None)
        wc.lpszClassName = "PythonTaskbarDemo"
        wc.lpfnWndProc = {win32con.WM_DESTROY: self.OnDestroy, }
        classAtom = win32gui.RegisterClass(wc)
        style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
        self.hwnd = win32gui.CreateWindow(classAtom, "Taskbar Demo", style,
                                            0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT,
                                            0, 0, hinst, None)
        hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
        nid = (self.hwnd, 0, win32gui.NIF_ICON, win32con.WM_USER + 20, hicon, "Demo")
        win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid)

    def showMsg(self, title, msg):
        # 原作者使用Shell_NotifyIconA方法代替包装后的Shell_NotifyIcon方法
        # 据称是不能win32gui structure, 我稀里糊涂搞出来了.
        # 具体对比原代码.
        nid = (self.hwnd,  # 句柄
                0,  # 托盘图标ID
                win32gui.NIF_INFO,  # 标识
                0,  # 回调消息ID
                0,  # 托盘图标句柄
                "TestMessage",  # 图标字符串
                msg,  # 气球提示字符串
                0,  # 提示的显示时间
                title,  # 提示标题
                win32gui.NIIF_INFO  # 提示用到的图标
                )
        win32gui.Shell_NotifyIcon(win32gui.NIM_MODIFY, nid)

    def OnDestroy(self, hwnd, msg, wparam, lparam):
        nid = (self.hwnd, 0)
        win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, nid)
        win32gui.PostQuitMessage(0)  # Terminate the app.




# 程序开始执行位置



t = TestTaskbarIcon()#右下角气泡提示

win = tkinter.Tk()  # 创建窗口
win.iconbitmap(".\\static\\icon2.ico")
win.title(biaoti)

win.geometry('700x395')

# B = tkinter.Button(win, text="启动", command=bntc, font=font)  # 窗口上面添加按钮
# B.pack(side='bottom',padx=3, pady=3)

var = tkinter.StringVar()#五菱平台信息
var.set(WL_ST+shuliang)
bjvar= tkinter.StringVar()#骏客平台信息
bjvar.set(JK_ST+shuliangBj)
status= tkinter.StringVar()#软件状态信息
status.set(STATUS_T+"启动助手")
loopvar= tkinter.StringVar()#总共查询次数
loopvar.set(LOOP_ST+str(regip_data['loop_sum']))

# 创建第一个容器
fm1 = Frame(win)
fm1.pack(side=BOTTOM,fill=X)
statusLB = Label(fm1, textvariable=status, font=font)#软件状态
statusLB.pack(side=LEFT,padx=10)

labelBj = Label(fm1, textvariable=bjvar, font=font)#骏客平台数量
labelBj.pack(side=RIGHT,padx=10)

label = Label(fm1, textvariable=var, font=font)#五菱平台数量
label.pack(side=RIGHT,padx=10)

labelLoop = Label(fm1, textvariable=loopvar, font=font)#五菱平台数量
labelLoop.pack(side=RIGHT,padx=10)



scroll = Scrollbar()#创建滚动条
scroll.pack(side=RIGHT, fill=Y,pady=3)#滚动条的位置
my_text = Text(win, width=300, height=40, font=font)  # 线索内容
my_text.pack(side=RIGHT, fill=tkinter.Y,padx=1, pady=3)


# 关联滚动条
scroll.config(command=my_text.yview)
my_text.config(yscrollcommand=scroll.set)


one_timer=threading.Timer(1,one_timer)#登录
one_timer.daemon = True
one_timer.start()

win.mainloop()
postretip(REGIP_URL,2,POSTTIME,False)#软件结束信息提交到后台

win32gui.DestroyWindow(t.hwnd)


